<?php
class ssfstream{
	static function mkdirable($dir) {
		return false;
	}

	static function writeable($file) {
		clearstatcache();
		if (is_file($file) || is_dir($file)) return is_writable($file);
		return false;
	}

	static function createdir($dir, $type = false) {
		return $type;
	}

	static function deletedir($file) {
		return false;
	}
	static function getStorType(){
		return class_exists('SaeStorage') ? SYSTEM_RUN_MODE : 'local';
	}
	static function getStorUrl($domain, $file){
		static $stor = null;
		if($stor == null) $stor = new SaeStorage();
		return $stor->getUrl($domain, $file);
	}
	static function writeToStorage($content, $name, $domain  = null){
		global $_SET;
		if(!class_exists('editorHelper')) require_once(ROOT_PATH . '/include/inc.editor.php');
		$ext = ssfbase::fileext($name);
		$dir = editorHelper::getUploadDir();
		$name = editorHelper::getRndFileName($ext);
		$storage = new SaeStorage();
		$attr = array(
				'expires' => 'access plus 1 year',
				'type' => ssfbase::getHttpMetaType($name)
		);
		if(!$domain){
			//sm modify
			$file_type = ssfbase::get_object('file_type')->get($name);
			$domain =  ($file_type == 'IMG' || $file_type == 'SWF') ? $_SET['attachment_img_domain'] : $_SET['attachment_file_domain'];
		}
		$try = 0;
		$url = '';
		while(true && $try < 3){
			$try++;
			$url = $storage->write($domain, $dir . $name , $content, -1, $attr);
			if($url) break;
		}
		return $url;
	}
}
?>